import axios, { AxiosResponse } from 'axios'
import { ElMessage } from 'element-plus'

// config
// const BASE_URL = "http://localhost:8080"
export const BASE_URL = 'http://localhost:8001'
export const TIMEOUT = 60000

// 创建axios实例
const request = axios.create({
	//一般项目
	baseURL: BASE_URL, // api 的 base_url  development   production
	timeout: TIMEOUT, // 请求超时时间
	withCredentials: true,
})

request.interceptors.response.use((res: AxiosResponse) => {
	if (res.status !== 200) {
		ElMessage({
			message: `错误：${res.data.message}`,
			type: 'success',
		})
	}
	return res
})

export { request }
